

cd /home/dev/ouer_code/meila_meigou_back_task

branch=dev

if [ -z $1 ]
 then
   branch=dev
 else 
   branch=$1
fi


#config=/home/dev/ouer_code/meila_meigou_back_task/dal/src/main/resources/env/config-test.properties

config=/home/dev/ouer_code/config/config-test.properties
dest=/home/dev/ouer_code/meila_meigou_back_task/dal/src/main/resources/env/config-test.properties

#read -p "输入key："  val
#sed -i "s/jdbc.driverClassName=.*/jdbc.driverClassName=$val/" $config
echo 'rm modify file'
/bin/rm $dest
/bin/rm /home/dev/ouer_code/meila_meigou_back_task/dal/src/main/resources/env/config-prod.properties

echo '================================ git update start  ====================================='
git fetch
git checkout --track origin/$branch

if [ $? -eq 0 ]
 then 
	echo $branch checkout from remote success
 else
 git checkout $branch
 if [ $? -eq 0 ]
	 then
		echo $branch checkout from local success
	 else
		exit -1
 fi
fi

git pull origin $branch
echo '================================ git update end ====================================='


echo 'copy ' $config $dest
cp  $config $dest

echo '================================ mvn start ====================================='
cat package-test.sh
sh package-test.sh
echo '================================ mvn end ====================================='



#. ~/.bashrc 

# kill
#ps -ef|grep tomcat | grep -v 'tail ' |awk '{print $2}' |xargs kill -9

tompid=$(netstat -anp|grep 7060 | grep 'java' | awk '{print $7}'|awk -F '/' '{print $1}')
echo $tompid | xargs kill -9
echo 'kill tomcat-back-task-7060 7060'

sleep 2

# backup
mv /ouer/tomcat-back-task-7060/webapps /ouer/tomcat-back-task-7060/backup/webapps.`date "+%Y%m%d%H%M"`
echo 'backup'

mkdir -p /ouer/tomcat-back-task-7060/webapps

#mv /home/dev/ouer_code/meila_meigou_back_task/frontend/bos/target/vdlm-bos-0.1.0-SNAPSHOT /ouer/tomcat-back-task-7060/webapps/vdlm-bos
#echo 'mv /home/dev/ouer_code/meila_meigou_back_task/frontend/bos/target/vdlm-bos-0.1.0-SNAPSHOT /ouer/tomcat-back-task-7060/webapps/vdlm-bos'

mv /home/dev/ouer_code/meila_meigou_back_task/frontend/task/target/vdlm-task-0.1.0-SNAPSHOT /ouer/tomcat-back-task-7060/webapps/vdlm-task
echo 'mv /home/dev/ouer_code/meila_meigou_back_task/frontend/task/target/vdlm-task-0.1.0-SNAPSHOT /ouer/tomcat-back-task-7060/webapps/vdlm-task'


# start
echo 'tomcat-back-task-7060 start'
/ouer/tomcat-back-task-7060/bin/startup.sh 

echo 'Done.'

